package com.ymatou.apigateway.testcase;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.apigateway.parameter.AesUtil;
import com.ymatou.apigateway.parameter.OpenapiReq;
import com.ymatou.apigateway.parameter.SkuStock;
import com.ymatou.apigateway.parameter.V1updateproductstockBean;
import com.ymatou.apigateway.service.OpenapiService;
import com.ymatou.apigateway.service.V1updateproductstockCall;
import com.ymatou.iapi.sellerproduct.service.AddNewSellerProductCall;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.database.model.Application;
import com.ymttest.database.model.AuthCode;
import com.ymttest.database.mongo.ProductDetailModelWapper;
import com.ymttest.database.mongo.YmtMongoDriverFactroy;
import com.ymttest.database.mongo.jproduct.CatalogsWapper;
import com.ymttest.database.sqlwapper.OpenApiWapper;
import com.ymttest.database.sqlwapper.YmtCatalogsIWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.JsonBeanHelper;
import com.ymttest.utils.MapUtil;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;
/**
*更新商品库存
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_V1updateproductstock {

	private static OpenapiReq openapiReq;
	private static V1updateproductstockBean v1updateproductstockBean;
	private static V1updateproductstockCall v1updateproductstockCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("更新商品库存");
	}

	@Before
	public void caseUp() {
		openapiReq = new OpenapiReq();
		openapiReq.setMethod("ymatou.sku.stock.update");

		v1updateproductstockBean = new V1updateproductstockBean();
		v1updateproductstockCall = new V1updateproductstockCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(v1updateproductstockCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_V1updateproductstock_001() {
		Logger.start(true, "根据sku_id更新商品库存");
		try {
			Integer sellerId = Integer.valueOf(EnvSetup
					.getData("productsellerid"));
			String sellerName = EnvSetup.getData("productsellername");

			JSONObject addProductBean = JsonBeanHelper
					.getJsonBean("com.ymatou.iapi.sellerproduct/AddNewSellerProduct/AddNewProductTpl_Tc10.json");
			JsonBeanHelper.updateJsonBean(addProductBean,
					MapUtil.hashMap("UserID", sellerId, "LoginID", sellerName));
			List<String> skuList = generateSKUList(8);
			setSkuForAddProduct(skuList, addProductBean);

			AddNewSellerProductCall addNewSellerProductCall = new AddNewSellerProductCall();
			String productId = addNewSellerProductCall
					.callAndGetReturnData(addProductBean).getJSONObject("Data")
					.getString("ProductID");
			Logger.comment("ProductId: " + productId);

			//修改stock
			Map<String, Object> skuAndStockMap = generateSKUStock(skuList);

			List<SkuStock> skuStocks = new ArrayList<SkuStock>();

			JSONArray skuStockArray = new JSONArray();
			for (String key : skuAndStockMap.keySet()) {
				JSONObject ele = new JSONObject();
				try {
					SkuStock skuStock = new SkuStock();
					skuStock.setOuter_sku_id(key);
					skuStock.setStock_num(Integer.parseInt(skuAndStockMap.get(
							key).toString()));

					skuStocks.add(skuStock);

				} catch (Exception e) {
					e.printStackTrace();
				}

			}

			v1updateproductstockBean.setSku_stocks(skuStocks);

			OpenApiWapper openApiWapper = new OpenApiWapper();

			Application application = openApiWapper
					.selectApplicationBySellerId(
							Long.parseLong(EnvSetup.getData("productsellerid")))
					.get(0);

			String app_id = application.getApp_id();
			String app_secret = application.getApp_secret();

			AuthCode authCode = openApiWapper.selectAuthCodeByAppId(app_id)
					.get(0);

			openapiReq.setApp_id(app_id);
			openapiReq.setSign_method("MD5");
			openapiReq.setAuth_code(authCode.getAuth_code());
			openapiReq.setTimestamp(YMTDateUtil.getSysTime());
			openapiReq.setNonce_str(TestDataManager.getRandomNum(31));
			openapiReq.setBiz_content(new FormatUtil()
					.beanToGSONString(v1updateproductstockBean));
			openapiReq.setSign(OpenapiService.generateMD5(openapiReq,
					AesUtil.decrypt(app_secret)));

			String url = String
					.format("http://apigateway.ymatou.com/apigateway/v1?app_id=%s&method=ymatou.sku.stock.update",
							app_id);
			v1updateproductstockCall.setUrl(url);

			v1updateproductstockCall.setData(openapiReq);
			v1updateproductstockCall.callService();

			JSONObject retBean = new JSONObject(
					v1updateproductstockCall.getReturnData());

			Logger.verifyEquals("0000", v1updateproductstockCall.getCode(),
					"验证Code");

			checkStockBySku(
					retBean.getJSONObject("content").getJSONArray("results"),
					skuAndStockMap);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_V1updateproductstock_002() {
		Logger.start(true, "更新商品库存-SkuId不存在");
		try {
			List<SkuStock> skuStocks = new ArrayList<SkuStock>();

			SkuStock skuStock = new SkuStock();
			//			skuStock.setOuter_sku_id("SKU966300381");
			skuStock.setStock_num(3);

			skuStocks.add(skuStock);

			v1updateproductstockBean.setSku_stocks(skuStocks);

			OpenApiWapper openApiWapper = new OpenApiWapper();

			Application application = openApiWapper
					.selectApplicationBySellerId(
							(long) Integer.parseInt(EnvSetup
									.getData("SellerId"))).get(0);

			String app_id = application.getApp_id();
			String app_secret = application.getApp_secret();

			AuthCode authCode = openApiWapper.selectAuthCodeByAppId(app_id)
					.get(0);

			openapiReq.setApp_id(app_id);
			openapiReq.setSign_method("MD5");
			openapiReq.setAuth_code(authCode.getAuth_code());
			openapiReq.setTimestamp(YMTDateUtil.getSysTime());
			openapiReq.setNonce_str(TestDataManager.getRandomNum(31));
			openapiReq.setBiz_content(new FormatUtil()
					.beanToGSONString(v1updateproductstockBean));
			openapiReq.setSign(OpenapiService.generateMD5(openapiReq,
					AesUtil.decrypt(app_secret)));

			String url = String
					.format("http://apigateway.ymatou.com/apigateway/v1?app_id=%s&method=ymatou.sku.stock.update",
							app_id);
			v1updateproductstockCall.setUrl(url);

			v1updateproductstockCall.setData(openapiReq);
			v1updateproductstockCall.callService();

			JSONObject retBean = new JSONObject(
					v1updateproductstockCall.getReturnData());

			Logger.verifyEquals("0001", v1updateproductstockCall.getCode(),
					"验证Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_V1updateproductstock_003() {
		Logger.start(true, "更新商品库存-SkuId空");
		try {
			List<SkuStock> skuStocks = new ArrayList<SkuStock>();

			SkuStock skuStock = new SkuStock();
			//skuStock.setOuter_sku_id("SKU966300381");
			skuStock.setStock_num(3);

			skuStocks.add(skuStock);

			v1updateproductstockBean.setSku_stocks(skuStocks);

			OpenApiWapper openApiWapper = new OpenApiWapper();

			Application application = openApiWapper
					.selectApplicationBySellerId(
							(long) Integer.parseInt(EnvSetup
									.getData("SellerId"))).get(0);

			String app_id = application.getApp_id();
			String app_secret = application.getApp_secret();

			AuthCode authCode = openApiWapper.selectAuthCodeByAppId(app_id)
					.get(0);

			openapiReq.setApp_id(app_id);
			openapiReq.setSign_method("MD5");
			openapiReq.setAuth_code(authCode.getAuth_code());
			openapiReq.setTimestamp(YMTDateUtil.getSysTime());
			openapiReq.setNonce_str(TestDataManager.getRandomNum(31));
			openapiReq.setBiz_content(new FormatUtil()
					.beanToGSONString(v1updateproductstockBean));
			openapiReq.setSign(OpenapiService.generateMD5(openapiReq,
					AesUtil.decrypt(app_secret)));

			String url = String
					.format("http://apigateway.ymatou.com/apigateway/v1?app_id=%s&method=ymatou.sku.stock.update",
							app_id);
			v1updateproductstockCall.setUrl(url);

			v1updateproductstockCall.setData(openapiReq);
			v1updateproductstockCall.callService();

			JSONObject retBean = new JSONObject(
					v1updateproductstockCall.getReturnData());

			Logger.verifyEquals("0001", v1updateproductstockCall.getCode(),
					"验证Code");

			Logger.verifyEquals("outer_sku_id 或 sku_id 必传一个.",
					v1updateproductstockCall.getMessage(), "验证message");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_V1updateproductstock_004() {
		Logger.start(true, "更新商品库存-stock_num负数");
		try {
			List<SkuStock> skuStocks = new ArrayList<SkuStock>();

			SkuStock skuStock = new SkuStock();
			skuStock.setOuter_sku_id("SKU966300381");
			skuStock.setStock_num(-3);

			skuStocks.add(skuStock);

			v1updateproductstockBean.setSku_stocks(skuStocks);

			OpenApiWapper openApiWapper = new OpenApiWapper();

			Application application = openApiWapper
					.selectApplicationBySellerId(
							(long) Integer.parseInt(EnvSetup
									.getData("SellerId"))).get(0);

			String app_id = application.getApp_id();
			String app_secret = application.getApp_secret();

			AuthCode authCode = openApiWapper.selectAuthCodeByAppId(app_id)
					.get(0);

			openapiReq.setApp_id(app_id);
			openapiReq.setSign_method("MD5");
			openapiReq.setAuth_code(authCode.getAuth_code());
			openapiReq.setTimestamp(YMTDateUtil.getSysTime());
			openapiReq.setNonce_str(TestDataManager.getRandomNum(31));
			openapiReq.setBiz_content(new FormatUtil()
					.beanToGSONString(v1updateproductstockBean));
			openapiReq.setSign(OpenapiService.generateMD5(openapiReq,
					AesUtil.decrypt(app_secret)));

			String url = String
					.format("http://apigateway.ymatou.com/apigateway/v1?app_id=%s&method=ymatou.sku.stock.update",
							app_id);
			v1updateproductstockCall.setUrl(url);

			v1updateproductstockCall.setData(openapiReq);
			v1updateproductstockCall.callService();

			JSONObject retBean = new JSONObject(
					v1updateproductstockCall.getReturnData());

			Logger.verifyEquals("0001", v1updateproductstockCall.getCode(),
					"验证Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_V1updateproductstock_005() {
		Logger.start(true, "更新商品库存-stock_num空");
		try {
			List<SkuStock> skuStocks = new ArrayList<SkuStock>();

			SkuStock skuStock = new SkuStock();
			skuStock.setOuter_sku_id("SKU966300381");

			skuStocks.add(skuStock);

			v1updateproductstockBean.setSku_stocks(skuStocks);

			OpenApiWapper openApiWapper = new OpenApiWapper();

			Application application = openApiWapper
					.selectApplicationBySellerId(
							(long) Integer.parseInt(EnvSetup
									.getData("SellerId"))).get(0);

			String app_id = application.getApp_id();
			String app_secret = application.getApp_secret();

			AuthCode authCode = openApiWapper.selectAuthCodeByAppId(app_id)
					.get(0);

			openapiReq.setApp_id(app_id);
			openapiReq.setSign_method("MD5");
			openapiReq.setAuth_code(authCode.getAuth_code());
			openapiReq.setTimestamp(YMTDateUtil.getSysTime());
			openapiReq.setNonce_str(TestDataManager.getRandomNum(31));
			openapiReq.setBiz_content(new FormatUtil()
					.beanToGSONString(v1updateproductstockBean));
			openapiReq.setSign(OpenapiService.generateMD5(openapiReq,
					AesUtil.decrypt(app_secret)));

			String url = String
					.format("http://apigateway.ymatou.com/apigateway/v1?app_id=%s&method=ymatou.sku.stock.update",
							app_id);
			v1updateproductstockCall.setUrl(url);

			v1updateproductstockCall.setData(openapiReq);
			v1updateproductstockCall.callService();

			JSONObject retBean = new JSONObject(
					v1updateproductstockCall.getReturnData());

			Logger.verifyEquals("0001", v1updateproductstockCall.getCode(),
					"验证Code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_V1updateproductstock_006() {
		Logger.start(true, "更新商品库存-stock_num溢出-不好模拟");
		try {
			List<SkuStock> skuStocks = new ArrayList<SkuStock>();

			SkuStock skuStock = new SkuStock();
			skuStock.setOuter_sku_id("SKU966300381");
			skuStock.setStock_num(38888888);

			skuStocks.add(skuStock);

			v1updateproductstockBean.setSku_stocks(skuStocks);

			OpenApiWapper openApiWapper = new OpenApiWapper();

			Application application = openApiWapper
					.selectApplicationBySellerId(
							(long) Integer.parseInt(EnvSetup
									.getData("SellerId"))).get(0);

			String app_id = application.getApp_id();
			String app_secret = application.getApp_secret();

			AuthCode authCode = openApiWapper.selectAuthCodeByAppId(app_id)
					.get(0);

			openapiReq.setApp_id(app_id);
			openapiReq.setSign_method("MD5");
			openapiReq.setAuth_code(authCode.getAuth_code());
			openapiReq.setTimestamp(YMTDateUtil.getSysTime());
			openapiReq.setNonce_str(TestDataManager.getRandomNum(31));
			openapiReq.setBiz_content(new FormatUtil()
					.beanToGSONString(v1updateproductstockBean));
			openapiReq.setSign(OpenapiService.generateMD5(openapiReq,
					AesUtil.decrypt(app_secret)));

			String url = String
					.format("http://apigateway.ymatou.com/apigateway/v1?app_id=%s&method=ymatou.sku.stock.update",
							app_id);
			v1updateproductstockCall.setUrl(url);

			v1updateproductstockCall.setData(openapiReq);
			v1updateproductstockCall.callService();

			JSONObject retBean = new JSONObject(
					v1updateproductstockCall.getReturnData());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_V1updateproductstock_007() {
		Logger.start(true, "更新他人商品库存");
		try {
			Integer sellerId = Integer.valueOf(EnvSetup
					.getData("productsellerid"));
			String sellerName = EnvSetup.getData("productsellername");

			JSONObject addProductBean = JsonBeanHelper
					.getJsonBean("com.ymatou.iapi.sellerproduct/AddNewSellerProduct/AddNewProductTpl_Tc10.json");
			JsonBeanHelper.updateJsonBean(addProductBean,
					MapUtil.hashMap("UserID", sellerId, "LoginID", sellerName));
			List<String> skuList = generateSKUList(8);
			setSkuForAddProduct(skuList, addProductBean);

			AddNewSellerProductCall addNewSellerProductCall = new AddNewSellerProductCall();
			String productId = addNewSellerProductCall
					.callAndGetReturnData(addProductBean).getJSONObject("Data")
					.getString("ProductID");
			Logger.comment("ProductId: " + productId);

			//修改stock
			Map<String, Object> skuAndStockMap = generateSKUStock(skuList);

			List<SkuStock> skuStocks = new ArrayList<SkuStock>();

			JSONArray skuStockArray = new JSONArray();
			for (String key : skuAndStockMap.keySet()) {
				JSONObject ele = new JSONObject();
				try {
					SkuStock skuStock = new SkuStock();
					skuStock.setOuter_sku_id(key);
					skuStock.setStock_num(Integer.parseInt(skuAndStockMap.get(
							key).toString()));

					skuStocks.add(skuStock);

				} catch (Exception e) {
					e.printStackTrace();
				}

			}

			v1updateproductstockBean.setSku_stocks(skuStocks);

			OpenApiWapper openApiWapper = new OpenApiWapper();

			Application application = openApiWapper
					.selectApplicationBySellerId(
							(long) Integer.parseInt(EnvSetup
									.getData("SellerId2"))).get(0);

			String app_id = application.getApp_id();
			String app_secret = application.getApp_secret();

			AuthCode authCode = openApiWapper.selectAuthCodeByAppId(app_id)
					.get(0);

			openapiReq.setApp_id(app_id);
			openapiReq.setSign_method("MD5");
			openapiReq.setAuth_code(authCode.getAuth_code());
			openapiReq.setTimestamp(YMTDateUtil.getSysTime());
			openapiReq.setNonce_str(TestDataManager.getRandomNum(31));
			openapiReq.setBiz_content(new FormatUtil()
					.beanToGSONString(v1updateproductstockBean));
			openapiReq.setSign(OpenapiService.generateMD5(openapiReq,
					AesUtil.decrypt(app_secret)));

			String url = String
					.format("http://apigateway.ymatou.com/apigateway/v1?app_id=%s&method=ymatou.sku.stock.update",
							app_id);
			v1updateproductstockCall.setUrl(url);

			v1updateproductstockCall.setData(openapiReq);
			v1updateproductstockCall.callService();

			JSONObject retBean = new JSONObject(
					v1updateproductstockCall.getReturnData());

			Logger.verifyEquals("0000", v1updateproductstockCall.getCode(),
					"验证Code");

			JSONArray jsonArray = retBean.getJSONObject("content")
					.getJSONArray("results");

			for (int j = 0; j < jsonArray.length(); j++) {

				Logger.verifyEquals(false, jsonArray.getJSONObject(j)
						.getBoolean("success"), "返回报文检查");
				Logger.verifyEquals("无效的SKUID", jsonArray.getJSONObject(j)
						.getString("msg"), "返回报文msg检查");
			}

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_V1updateproductstock_008() {
		Logger.start(true, "根据catalog_id更新商品库存");
		try {
			Integer sellerId = Integer.valueOf(EnvSetup
					.getData("productsellerid"));
			String sellerName = EnvSetup.getData("productsellername");

			JSONObject addProductBean = JsonBeanHelper
					.getJsonBean("com.ymatou.iapi.sellerproduct/AddNewSellerProduct/AddNewProductTpl_Tc10.json");
			JsonBeanHelper.updateJsonBean(addProductBean,
					MapUtil.hashMap("UserID", sellerId, "LoginID", sellerName));
			List<String> skuList = generateSKUList(8);
			setSkuForAddProduct(skuList, addProductBean);

			AddNewSellerProductCall addNewSellerProductCall = new AddNewSellerProductCall();
			String productId = addNewSellerProductCall
					.callAndGetReturnData(addProductBean).getJSONObject("Data")
					.getString("ProductID");
			Logger.comment("ProductId: " + productId);

			//修改stock
			Map<String, Object> skuAndStockMap = generateSKUStock(skuList);

			List<SkuStock> skuStocks = new ArrayList<SkuStock>();

			JSONArray skuStockArray = new JSONArray();

			for (String key : skuAndStockMap.keySet()) {
				JSONObject ele = new JSONObject();
				try {

					SkuStock skuStock = new SkuStock();

					List<Map> maps = new YmtCatalogsIWapper()
							.selectCatalogsByProductIdandSku(productId, key);

					String catalog_id = (String) maps.get(0).get("sCatalogId");

					skuStock.setSku_id(catalog_id);
					skuStock.setStock_num(Integer.parseInt(skuAndStockMap.get(
							key).toString()));

					skuStocks.add(skuStock);

				} catch (Exception e) {
					e.printStackTrace();
				}

			}

			v1updateproductstockBean.setSku_stocks(skuStocks);

			OpenApiWapper openApiWapper = new OpenApiWapper();

			Application application = openApiWapper
					.selectApplicationBySellerId(
							Long.parseLong(EnvSetup.getData("productsellerid")))
					.get(0);

			String app_id = application.getApp_id();
			String app_secret = application.getApp_secret();

			AuthCode authCode = openApiWapper.selectAuthCodeByAppId(app_id)
					.get(0);

			openapiReq.setApp_id(app_id);
			openapiReq.setSign_method("MD5");
			openapiReq.setAuth_code(authCode.getAuth_code());
			openapiReq.setTimestamp(YMTDateUtil.getSysTime());
			openapiReq.setNonce_str(TestDataManager.getRandomNum(31));
			openapiReq.setBiz_content(new FormatUtil()
					.beanToGSONString(v1updateproductstockBean));
			openapiReq.setSign(OpenapiService.generateMD5(openapiReq,
					AesUtil.decrypt(app_secret)));

			String url = String
					.format("http://apigateway.ymatou.com/apigateway/v1?app_id=%s&method=ymatou.sku.stock.update",
							app_id);
			v1updateproductstockCall.setUrl(url);

			v1updateproductstockCall.setData(openapiReq);
			v1updateproductstockCall.callService();

			JSONObject retBean = new JSONObject(
					v1updateproductstockCall.getReturnData());

			Logger.verifyEquals("0000", v1updateproductstockCall.getCode(),
					"验证Code");

			checkStockBySku(
					retBean.getJSONObject("content").getJSONArray("results"),
					skuAndStockMap);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	public static void setSkuForAddProduct(List<String> skuList,
			JSONObject addProdRequest) throws JSONException {
		JSONArray catalogAry = addProdRequest.getJSONObject("Product")
				.getJSONArray("Catalogs");
		int minNum = Math.min(skuList.size(), catalogAry.length());
		for (int i = 0; i < minNum; i++) {
			catalogAry.getJSONObject(i).put("SKU", skuList.get(i));
		}
	}

	public static List<String> generateSKUList(int num) {
		List<String> skuList = new ArrayList<>();
		for (int i = 0; i < num; i++) {
			skuList.add("SKU" + TestDataManager.getRandomIntNum(10));
		}
		return skuList;
	}

	public static Map<String, Object> generateSKUStock(List<String> skuList) {
		Map<String, Object> retMap = new HashMap<>();
		skuList.forEach(ele -> {
			int stock = TestDataManager.getRandomIntNum(2);
			retMap.put(ele, stock);
			Logger.comment("SKU: " + ele + ", stock: " + stock);
		});
		return retMap;
	}

	public static void checkStockBySku(JSONArray skuResults,
			Map<String, Object> skuIdandStockMap) throws Exception {
		YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();

		for (String skuId : skuIdandStockMap.keySet()) {
			//返回报文检查
			boolean isFoundInRet = false;
			for (int j = 0; j < skuResults.length(); j++) {
				if (skuResults.getJSONObject(j).getString("outer_sku_id")
						.equals(skuId)) {
					Logger.verifyEquals(true, skuResults.getJSONObject(j)
							.getBoolean("success"), "ExecSuccess 返回报文检查");
					Logger.verifyEquals("成功", skuResults.getJSONObject(j)
							.getString("msg"), "msg 返回报文检查");

					isFoundInRet = true;
					break;
				}
			}
			Logger.verifyEquals(true, isFoundInRet, "SKU:" + skuId
					+ ",在返回报文中是否存在");

			//期待库存
			int tgtStock = Integer.parseInt(skuIdandStockMap.get(skuId)
					.toString());

			List<Map> retList = ymtCatalogsIWapper.selectProductIdBySku(skuId);
			Logger.verifyEquals(1, retList.size(), "SKU:" + skuId
					+ ", 应该只有一个对应的catalog");
			Map<String, Object> ret = retList.get(0);

			String productId = ret.get("sProductId").toString();
			String catalogId = ret.get("sCatalogId").toString();
			int actStockInSql = Integer.parseInt(ret.get("iNum").toString());

			//sql
			Logger.verifyEquals(tgtStock, actStockInSql, "sql中库存检查 catalogId:"
					+ catalogId + ", sku:" + skuId);

			//mongo
			if (YmtMongoDriverFactroy.isNewMongoCheck()) {
				ProductDetailModelWapper productDetailModelWapper = new ProductDetailModelWapper();
				Map<String, Object> dataInMgo = productDetailModelWapper
						.getProductId(productId);
				JSONArray catalogAry = new JSONArray(dataInMgo.get(
						"CatalogList").toString());

				boolean isFound = false;
				for (int i = 0; i < catalogAry.length(); i++) {
					JSONObject catalogBean = catalogAry.getJSONObject(i);
					if (catalogBean.getString("CatalogId").equals(catalogId)) {
						Logger.verifyEquals(skuId,
								catalogBean.getString("SKU"),
								"Mongo中sku检查 catalogId:" + catalogId + ", sku:"
										+ skuId);

						JSONArray stockList = catalogBean
								.getJSONArray("StockList");
						for (int k = 0; k < stockList.length(); k++) {
							if (stockList.getJSONObject(k).getInt("StockType") == 0) {
								Logger.verifyEquals(tgtStock, stockList
										.getJSONObject(k).getInt("Stock"),
										"Mongo中库存检查 catalogId:" + catalogId
												+ ", sku:" + skuId);
							}
						}

						isFound = true;
						break;
					}
				}

				Logger.verifyEquals(true, isFound, "scatalogId:" + catalogId
						+ ", sku:" + skuId + ", 应该在mongo库中存在");
			};

			//java mongo
			if (YmtMongoDriverFactroy.isNewJavaMgoCheck()) {
				CatalogsWapper catalogsWapper = new CatalogsWapper();
				Map<String, Object> dataInMgo = catalogsWapper
						.getByCatalogId(catalogId);
				int actStockInMgo = Integer.parseInt(dataInMgo.get("stock")
						.toString());
				Logger.verifyEquals(skuId, dataInMgo.get("sku").toString(),
						"Java Mongo中sku检查 catalogId:" + catalogId + ", sku:"
								+ skuId);
				Logger.verifyEquals(tgtStock, actStockInMgo,
						"Java Mongo中库存检查 catalogId:" + catalogId + ", sku:"
								+ skuId);
			}
		}

	}

}